package com.quanxiaoha.weblog.common.service.impl;

import com.quanxiaoha.weblog.common.entity.ScheduleSkillModel;
import com.quanxiaoha.weblog.common.domain.mapper.ScheduleSkillModelMapper;
import com.quanxiaoha.weblog.common.service.IScheduleSkillModelService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Roy
 * @since 2025-06-13
 */
@Service
public class ScheduleSkillModelServiceImpl extends ServiceImpl<ScheduleSkillModelMapper, ScheduleSkillModel> implements IScheduleSkillModelService {

    @Override
    public boolean createScheduleSkillModel(ScheduleSkillModel scheduleSkillModel) {
        return save(scheduleSkillModel);
    }

    @Override
    public boolean deleteScheduleSkillModelById(Long id) {
        return removeById(id);
    }

    @Override
    public boolean updateScheduleSkillModel(ScheduleSkillModel scheduleSkillModel) {
        return updateById(scheduleSkillModel);
    }

    @Override
    public ScheduleSkillModel getScheduleSkillModelById(Long id) {
        return getById(id);
    }

    @Override
    public IPage<ScheduleSkillModel> pageScheduleSkillModel(Page<ScheduleSkillModel> page, ScheduleSkillModel scheduleSkillModel) {
        LambdaQueryWrapper<ScheduleSkillModel> queryWrapper = new LambdaQueryWrapper<>();
        
        // 根据实体类中的非空字段进行条件查询
        if (scheduleSkillModel != null) {
            // 这里需要根据 ScheduleSkillModel 的具体字段来添加查询条件
            // 示例：如果实体类中有 name 字段
            // if (StringUtils.hasText(scheduleSkillModel.getName())) {
            //     queryWrapper.like(ScheduleSkillModel::getName, scheduleSkillModel.getName());
            // }
        }
        
        // 按创建时间降序排序
        queryWrapper.orderByDesc(ScheduleSkillModel::getCreateTime);
        
        return page(page, queryWrapper);
    }
}
